package com.dayuanit.dy15.atm.servlet;

import com.alibaba.fastjson.JSON;
import com.dayuanit.dy15.atm.dto.ResponseDTO;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;

public class BaseServlet extends HttpServlet {

    protected void responseByAjax(ResponseDTO responseDTO, HttpServletResponse response) {
        String msg = JSON.toJSONString(responseDTO);

        try {
            response.setContentType("application/json; charset=utf-8");
            ServletOutputStream outputStream = response.getOutputStream();
            outputStream.write(msg.getBytes("utf-8"));
            outputStream.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
